import configparser
import json

failname = 'test.ini'

cfg = configparser.ConfigParser()

cfg.set('DEFAULT', 'a', 'test')

cfg.add_section('mysql')
x = cfg['mysql'] = {'default-charecter-set' :  'utf-8','a': '1000'}
#print(type(x),x)

cfg.add_section('mysqld')
x = cfg['mysqld'] = {'datadir':'/dbserver/data', 'port':'33060', 'character-set-server':'utf-8',\
                 'sql_mode':'NO_ENGINE_SUBSTITUTION,STRICT_TRANS_RABLES'}
#print(type(x),x)

with open(failname, 'w') as f:
    cfg.write(f)

d = {}
for i in cfg.sections():
    d[i] = dict(cfg.items(i))
    print(d)

with open('test.json', 'w') as f:
    json.dump(d,f)


# 你应该从文件里面读出相应的信息，而不是自己写出来，这样工作处理起来没有针对性
